<?php
$this->display(tpl('head',true)); 
$bt[intval($setting['ziduan_bitian'])]=" checked";
if(intval($setting['ziduan_bitian'])){
	$zzyz="";
}else{
	$zzyz=" style='display: none;'";
}
$zhengzeyanzheng[$setting['ziduan_zhengzeyanzheng']]="selected";
if($setting[ziduan_xssguolv]){
	$XSS="checked";
}
if($setting){
	$selectleibie[$setting['ziduan_leibie']]="selected";
}else{
	$selectleibie['Text']="selected";
}
?>
<style>
	.layui-tab{
		padding-left: 20px;
	}
	.layui-field-box{
		color: red;
	}
	.layui-form-select {
	    position: relative;
	    width: 30%;
	}
	.layui-input-my {
	    display: block;
	    width: 30%;
	    padding-left: 10px;
	    float: left;
	}
	.layui-input-block p{
		margin-top: 10px;
		color: #aaa;
		width: 100%;
		float: left;
	}
	.layui-input-block span{
		height: 35px;
		line-height: 35px;
		padding-left: 10px;
	}
	.layui-textarea {
	    display: block;
	    width: 30%;
	    padding-left: 10px;
	}
	.layui-form-switch {
	    width: 80px;
		height: 25px;
		line-height: 25px;
	}
	.layui-form-switch em {
	    width: 50px;
	}
	.layui-form-onswitch i {
	    left: 70px;
	    background-color: #fff;
	}
	.name{
		height: 35px;
		line-height: 35px;
	}
</style>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>创建字段</legend>
</fieldset>
<form class="layui-form" method="post">
<div class="layui-tab">
  <ul class="layui-tab-title">
    <li class="layui-this">网站设置</li>
    <li>数据验证</li>
  </ul>
  <div class="layui-tab-content">
  	<div class="layui-tab-item layui-show">
    	<div class="layui-form-item layui-form-text">
    		<label class="layui-form-label">所属模型</label>
    		<div class="layui-input-block name">
    			<?php echo $data[name] ?>
    		</div>
    	</div>
    	<div class="layui-form-item layui-form-text">
    		<label class="layui-form-label">字段名称</label>
    		<div class="layui-input-block">
    			<input name="setting[ziduan_mingcheng]" id="ziduanmingcheng" value="<?php echo $setting[ziduan_mingcheng] ?>"  class="layui-input layui-input-my" type="text">
    			<p>为字段取个名字，例如：文档标题、作者、来源等等</p>
    		</div>
    	</div>
    	<div class="layui-form-item layui-form-text">
    		<label class="layui-form-label">字段KEY</label>
    		<div class="layui-input-block">
    			<input name="setting[ziduan_key]" id="field_key" value="<?php echo $setting[ziduan_key] ?>"  class="layui-input layui-input-my" type="text">
    			<p>只能由英文字母、数字组成可带下划线_，最少3个字符</p>
    		</div>
    	</div>
    	
    	<div class="layui-form-item">
    		<label class="layui-form-label">类别</label>
    		<div class="layui-input-block">
    			<select name="setting[ziduan_leibie]" lay-filter="field_type">
    				<option value="">请选择一个类别</option>
    				<option value="Checkbox" <?php echo $selectleibie['Checkbox'] ?>>复选框(Checkbox) </option>
    				<option value="Date" <?php echo $selectleibie['Date'] ?>> 日期时间(Date) </option>
    				<option value="File" <?php echo $selectleibie['File'] ?>> 单文件(File) </option>
    				<option value="Files" <?php echo $selectleibie['Files'] ?>> 多文件(Files) </option>
    				<option value="Radio" <?php echo $selectleibie['Radio'] ?>> 单选按钮(Radio) </option>
    				<option value="Select" <?php echo $selectleibie['Select'] ?>> 下拉选择(Select) </option>
    				<option value="Text" <?php echo $selectleibie['Text'] ?>> 单行文本(Text) </option>
    				<option value="Textarea" <?php echo $selectleibie['Textarea'] ?>> 多行文本(Textarea) </option>
    				<option value="Ueditor" <?php echo $selectleibie['Ueditor'] ?>> 百度编辑器(Ueditor) </option>
    			</select>
    		</div>
    	</div>
		<div id="shuxing"><?php echo $html ?></div>
    	<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="hidden" name="step" id="step" value="post" />
				<input type="hidden" name="id" value="<?php echo $id ?>" />
				<input type="hidden" name="setting[reorder]"  value="<?php echo $setting[reorder] ?>" >
<?php if(M_METHOD=="edit_field"){ ?>
				<input type="hidden" name="field_key" value="<?php echo $field_key ?>" />
				<button class="layui-btn">修改字段</button>
<?php }else{ ?>
				<button class="layui-btn">创建字段</button>
<?php } ?>	
			</div>
		</div>
  </div>
    <div class="layui-tab-item">
    	<div class="layui-form-item">
    		<label class="layui-form-label">是否必填项</label>
    		<div class="layui-input-block">
    			<input name="setting[ziduan_bitian]" value="1" lay-filter="if_required" title="是" type="radio" <?php echo $bt[1] ?>>
    			<input name="setting[ziduan_bitian]" value="0" lay-filter="if_required" title="不是" type="radio"  <?php echo $bt[0] ?>>
    		</div>
    	</div>
    	<div class="layui-form-item" id="bt1"<?php echo $zzyz ?>>
    		<label class="layui-form-label">正则验证</label>
    		<div class="layui-input-block">
    			<input name="setting[ziduan_zhengzeyanzheng]" value="<?php echo $setting[ziduan_zhengzeyanzheng] ?>" id="validate_pattern" class="layui-input layui-input-my">
    			<select lay-filter="field_validate_pattern">
    				<option value="">正则验证</option>
    				<option <?php echo $zhengzeyanzheng['/^[0-9.-]+$/'] ?> value="/^[0-9.-]+$/">数字</option>
    				<option <?php echo $zhengzeyanzheng['/^[0-9-]+$/'] ?> value="/^[0-9-]+$/">整数</option>
    				<option <?php echo $zhengzeyanzheng['/^[a-z]+$/i'] ?> value="/^[a-z]+$/i">字母</option>
    				<option <?php echo $zhengzeyanzheng['/^[0-9a-z]+$/i'] ?> value="/^[0-9a-z]+$/i">数字+字母</option>
    				<option <?php echo $zhengzeyanzheng['/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/'] ?> value="/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/">E-mail</option>
    				<option <?php echo $zhengzeyanzheng['/^[0-9]{5,20}$/'] ?> value="/^[0-9]{5,20}$/">QQ</option>
    				<option <?php echo $zhengzeyanzheng['/^http:\/\//'] ?> value="/^http:\/\//">URL链接</option>
    				<option <?php echo $zhengzeyanzheng['/^(1)[0-9]{10}$/'] ?> value="/^(1)[0-9]{10}$/">手机号码</option>
    				<option <?php echo $zhengzeyanzheng['/^[0-9-]{6,13}$/'] ?> value="/^[0-9-]{6,13}$/">电话号码</option>
    				<option <?php echo $zhengzeyanzheng['/^[0-9]{6}$/'] ?>value="/^[0-9]{6}$/">邮政编码</option>
    			</select>
    		</div>
    	</div>
    	<div class="layui-form-item"  id="bt2" <?php echo $zzyz ?>>
    		<label class="layui-form-label">验证提示</label>
    		<div class="layui-input-block">
    			<input name="setting[ziduan_yanzhengtishi]" class="layui-input layui-input-my" value="<?php echo $setting[ziduan_yanzhengtishi] ?>">
    			<p>当字段校验未通过时的提示信息，如“标题必须在80字以内”等等</p>
    		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">XSS过滤</label>
    		<div class="layui-input-block">
    			<input name="setting[ziduan_xssguolv]" value="0" id="ziduan_xssguolv" type="checkbox"  lay-filter="ziduan_xssguolv" lay-skin="switch" lay-text="已开启|已关闭" <?php echo $XSS ?>>
    		</div>
    	</div>
    	<div class="layui-form-item">
    		<label class="layui-form-label">字段提示</label>
    		<div class="layui-input-block">
    			<input name="setting[ziduan_tishi]" id="ziduan_tishi" class="layui-input layui-input-my"  value="<?php echo $setting[ziduan_tishi] ?>">
    			<p>对字段简短的提示，来说明这个字段是用来干什么的</p>
    		</div>
    	</div>
    </div>
</div>
</div>
</div>
</form>
<script type="text/javascript">
	layui.use(['form','element'], function(){
	  	var form = layui.form;
	  	var element = layui.element;
		form.on('select(field_type)', function(data){
			htmlobj=$.ajax({url:"<?php echo admin_module_url ?>/module/ajax_field/type_"+data.value,async:false});
			$("#shuxing").html(htmlobj.responseText);
			form.render();
		});
		form.on('select(field_validate_pattern)', function(data){
			$("#validate_pattern").val(data.value);
		});
		form.on('radio(if_required)', function(data){
			if(data.value==1){
				document.getElementById("bt1").style.display="";
				document.getElementById("bt2").style.display="";
			}else{
				document.getElementById("bt1").style.display="none";
				document.getElementById("bt2").style.display="none";
			}
		});
		
		form.on('radio(ziduan_is_down)', function(data){
			if(data.value==1){
				$('#ziduan_down_url_list').show();
			}else{
				$('#ziduan_down_url_list').hide();
			}
		});
		form.on('radio(ziduan_play)', function(data){
			if(data.value=='video' || data.value=='audio'){
				$('#ziduan_play').show();
				$('#ziduan_play1').show();
				$('#ziduan_is_down').hide();
				$('#ziduan_down_url_list').hide();
			}else{
				$('#ziduan_play').hide();
				$('#ziduan_play1').hide();
				$('#ziduan_is_down').show();
				$('#ziduan_down_url_list').show();
			}
			
			if(data.value=='images'){
				$('#ziduan_is_down').hide();
				$('#ziduan_down_url_list').hide();
			}
		});
		form.on('radio(ziduan_is_play)', function(data){
			if(data.value==1){
				$('#ziduan_is_play').show();
			}else{
				$('#ziduan_is_play').hide();
			}
		});
		
		form.on('radio(ziduan_is_local)', function(data){
			if(data.value==1){
				$('#file_size').show();
			}else{
				$('#file_size').hide();
			}
		});
		
		form.on('switch(ziduan_xssguolv)', function(data){
		    if(this.checked==true){
		    	$("#ziduan_xssguolv").val('1');
		    	layer.tips('温馨提示：已开启XSS过滤', data.othis);
		    }else{
		    	$("#ziduan_xssguolv").val('0');
		    	layer.tips('温馨提示：已关闭XSS过滤', data.othis);
		    }
		});
	});
	
</script>

<?php $this->display(tpl('foot',true)); ?>
